<template>
	<view>
		<view class="item" v-for="(res, index) in siteList" :key="index" v-if="islogin==true">
			<view class="top" @click="choiceAddress(res)">
				<view class="name">{{ res.name }}</view>
				<view class="phone">{{ res.mobile }}</view>
				<view class="tag">
					<text v-if="res.is_default==1" style="background-color:red">默认</text>
					<text v-if="res.tag==0" style="background-color:#007AFF">家</text>
					<text v-if="res.tag==1" style="background-color:#007AFF">公司</text>
					<text v-if="res.tag==2" style="background-color:#007AFF">学校</text>
				</view>
			</view>
			<view class="bottom">
				<view style="width: 80%;">{{res.region}}{{res.address}}</view>
				<view>
					<image src="../../../static/Mine/edit.png" @tap="editaddres(res.id)"></image>
					<image src="../../../static/Mine/del.png" @tap="deladdres(res.id)"></image>
				</view>				
			</view>
		</view>
		<view class="item" v-for="(res, index) in siteList2" :key="index" v-if="islogin==false">
			<view class="top">
				<view class="name">{{ res.name }}</view>
				<view class="phone">{{ res.mobile }}</view>
				<view class="tag">
					<text style="background-color:red">默认</text>
					<text  style="background-color:#007AFF">家</text>
				</view>
			</view>
			<view class="bottom">
				<view style="width: 80%;">广东省深圳市宝安区 前海湾</view>
				<view >
					<image src="../../../static/Mine/edit.png" @tap="editaddres(res.id)"></image>
					<image src="../../../static/Mine/del.png" @tap="deladdres(res.id)"></image>
				</view>				
			</view>
		</view>
		<view class="bot_btn">
			<view class="btn btn2" @click="toAddSite">新建收货地址</view>
			<view class="btn ">导入微信地址</view>
		</view>
	</view>
</template>

<script>
	import {addresslist,addressedel} from '@/api/mine.js'
export default {
	data() {
		return {
			siteList: [],
			islogin:false,
			siteList2:[
					// {
					// 	id: 1,
					// 	name: '游X',
					// 	phone: '183****5523',
					// 	tag: [
					// 		{
					// 			tagText: '默认'
					// 		},
					// 		{
					// 			tagText: '家'
					// 		}
					// 	],
					// 	site: '广东省深圳市宝安区 自由路66号'
					// },
					// {
					// 	id: 2,
					// 	name: '李XX',
					// 	phone: '183****5555',
					// 	tag: [
					// 		{
					// 			tagText: '公司'
					// 		}
					// 	],
					// 	site: '广东省深圳市宝安区 翻身路xx号'
					// },
					// {
					// 	id: 3,
					// 	name: '王YY',
					// 	phone: '153****5555',
					// 	tag: [],
					// 	site: '广东省深圳市宝安区 平安路13号'
					// }
			],
			cart_ids:"",
			coupon_id:"",
		};
	},
	onLoad(point) {
		this.cart_ids=point.ids
		this.coupon_id=point.couponId
		this.getaddlist()
	},
	onShow() {
		this.getaddlist()
	},
	methods: {
		// 获取地址列表
		getaddlist(){
			addresslist().then(res=>{
				console.log(res)
				this.siteList=res.data.list
				this.islogin=true
			})
		},
		// 删除地址
		deladdres(id){
			addressedel({id:id}).then(res=>{
				console.log(res)
				if(res.status==200){
					uni.showToast({
						title:'删除成功',
						duration:2000,
					})
				}
			})
		},
		editaddres(id){
			uni.navigateTo({
			    url: '../address/addSite?type=1&id='+id,
				fail(fail) {
					console.log(fail)
				}
			});
		},
		toAddSite(){
			uni.navigateTo({
			    url: '../address/addSite',
				fail(fail) {
					console.log(fail)
				}
			});
		},
		//选择地址
		choiceAddress(res){
			console.log(res)
			uni.navigateTo({
				url:"/pages/orderPay/payment2?ids="+this.cart_ids+"&&addressId="+res.id+"&&couponId="+this.coupon_id
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.item {
	padding: 40rpx 20rpx;
	.top {
		display: flex;
		font-weight: bold;
		font-size: 34rpx;
		.phone {
			margin-left: 60rpx;
		}
		.tag {
			display: flex;
			font-weight: normal;
			align-items: center;
			text {
				display: block;
				width: 60rpx;
				height: 34rpx;
				line-height: 34rpx;
				color: #ffffff;
				font-size: 20rpx;
				border-radius: 6rpx;
				text-align: center;
				margin-left: 30rpx;
				background-color:rgb(49, 145, 253);
			}
		}
	}
	.bottom {
		display: flex;
		margin-top: 20rpx;
		font-size: 28rpx;
		justify-content: space-between;
		color: #999999;		
		image{
			margin-left: 20rpx;
			width: 50rpx;
			height: 50rpx;
		}
		
	}
}

.bot_btn{
	position: absolute;
	display: flex;
	justify-content: center;
	align-items: center;
	width: 95%;
	bottom: 30rpx;
	z-index: 999;
	padding: 20rpx;
}
.btn{
	margin-top: 10rpx;
	width: 50%;
	height: 90rpx;
	background-color: #00C049;
	display: block;
	float: right;
	border-radius: 50rpx;
	align-items: center;
	color: #fff;
	text-align: center;
	line-height: 90rpx;
	font-size: 35rpx;
	justify-content: center;
}
.btn2{
	background-color: #F76260;
	margin-right: 20rpx;
}

</style>
